import { ModelModeType } from '@/services/types/app'
import { BlockEnum } from '../../../types'
import type { NodeDefault } from '../../../types'
import { PromptSpeechType, type VideoGeneratorNodeType } from './types'
import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/components/workflow/constants'

const i18nPrefix = 'workflow.errorMsg'

const nodeDefault: NodeDefault<VideoGeneratorNodeType> = {
  defaultValue: {
    model: {
      provider: '',
      name: '',
      mode: ModelModeType.unset,
    },
    prompt_speech_type: PromptSpeechType.Clone,
    prompt_speech: {
      prompt_text: '',
      prompt_speech: ''
    },
    text: "",
    options: {
    },
  },
  getAvailablePrevNodes(isChatMode: boolean) {
    const nodes = isChatMode
      ? ALL_CHAT_AVAILABLE_BLOCKS
      : ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes(isChatMode: boolean) {
    const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
    return nodes
  },
  checkValid(payload: VideoGeneratorNodeType, t: any) {
    let errorMessages = ''
    const { model, text, prompt_speech, prompt_speech_type, prompt_speech_selector, prompt_speech_template } = payload
    if (!errorMessages && !text)
      errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.text`) })
    if (!errorMessages && !prompt_speech_type)
      errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.prompt_speech_type`) })
    if (!errorMessages && !model)
      errorMessages = t(`${i18nPrefix}.fieldRequired`, { field: t(`${i18nPrefix}.fields.model`) })

    return {
      isValid: !errorMessages,
      errorMessage: errorMessages,
    }
  },

}

export default nodeDefault
